const express = require('express')
const validate = require('express-validation')
const _ = require('lodash')
const moment = require('moment')
const cosAuthGenerator = require('../util/cosAuthGenerator')

const cosRouter = express.Router()

cosRouter.get('/auth', (req, res, next) => {
  const { filename, fsizeLimit } = req.query
  const options = {
    filename,
    fsizeLimit,
    deadline: moment().unix()
  }
  // const options = {
  //   method: req.method,
  //   pathname: req.pathname,
  //   query: req.query,
  //   headers: req.headers
  // }
  const upToken = cosAuthGenerator(options)
  res.json({ status: 200, msg: '签名生成成功', data: { upToken } })
})

module.exports = cosRouter
